//
//  FirstBarViewController.m
//  微运营
//
//  Created by 李光耀 on 16/3/21.
//  Copyright © 2016年 李光耀. All rights reserved.
//

#import "FirstBarViewController.h"
#import "eightTableViewCell.h"
#import "SameCityTableViewCell.h"
#import "ThinkYouLikeTableViewCell.h"

@interface FirstBarViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong)UITableView *tableView;
#warning 预留返回数组
@property (nonatomic, strong)NSMutableArray *thinkYouLikeArray;

@end

@implementation FirstBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
#warning 预留数组后期删
    self.thinkYouLikeArray = [[NSMutableArray alloc]init];
    _thinkYouLikeArray = @[@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9"];

    self.title = @"首页";
    self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.tableView registerClass:[eightTableViewCell class] forCellReuseIdentifier:@"eightTableViewCellIdentifier"];
    [self.tableView registerClass:[SameCityTableViewCell class] forCellReuseIdentifier:@"SameCityTableViewCellIdentifier"];
    [self.tableView registerClass:[ThinkYouLikeTableViewCell class] forCellReuseIdentifier:@"ThinkYouLikeTableViewCellIdentifier"];
    [self.view addSubview:_tableView];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - tableView 分区数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
#pragma mark - 自定义cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        eightTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"eightTableViewCellIdentifier"];
#warning 取消cell 点击颜色
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
        
    }else if (indexPath.section == 1) {
        SameCityTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SameCityTableViewCellIdentifier"];
#warning 取消cell 点击颜色
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
        
    }else {
        ThinkYouLikeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ThinkYouLikeTableViewCellIdentifier"];
#warning 取消cell 点击颜色
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
}

#pragma mark - 各分区返回row数量
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }else if (section == 1){
        return 1;
    }else{
        return _thinkYouLikeArray.count;
    }
}

#pragma mark - 分区视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        UIView *vv = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 100)];
        vv.backgroundColor = [UIColor whiteColor];
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, 12, 150, 50)];
        label.text = @"广告位";
        label.textColor = [UIColor orangeColor];
        label.font = [UIFont systemFontOfSize:20];
        vv.backgroundColor = [UIColor yellowColor];
        [vv addSubview:label];
        return vv;
    }else if(section == 1){
        UIView *vv = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 100)];
        vv.backgroundColor = [UIColor whiteColor];
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, 12, 150, 50)];
        label.text = @"同城服务商";
        label.textColor = [UIColor orangeColor];
        label.font = [UIFont systemFontOfSize:20];
        [vv addSubview:label];
        return vv;
        
    }else{
        UIView *vv = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 100)];
        vv.backgroundColor = [UIColor whiteColor];
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, 12, 150, 50)];
        label.text = @"猜你喜欢";
        label.textColor = [UIColor orangeColor];
        label.font = [UIFont systemFontOfSize:20];
        [vv addSubview:label];
        return vv;
        
    }

}

#pragma mark - 分区头视图大小
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 74;
    
}

#pragma mark - 分区脚
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 15;
}

#pragma mark - row 高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 210;
    }else if (indexPath.section == 1){
        return 180;
    }else{
        return 160;
    }
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
